package com.hongxun.project.assets.iMaterial.controller;

import java.util.List;

import com.hongxun.project.assets.iPoint.domain.IPoint;
import com.hongxun.project.assets.iPoint.service.IIPointService;
import com.hongxun.project.assets.pPoint.domain.PPoint;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hongxun.framework.aspectj.lang.annotation.Log;
import com.hongxun.framework.aspectj.lang.enums.BusinessType;
import com.hongxun.project.assets.iMaterial.domain.IMaterial;
import com.hongxun.project.assets.iMaterial.service.IIMaterialService;
import com.hongxun.framework.web.controller.BaseController;
import com.hongxun.framework.web.page.TableDataInfo;
import com.hongxun.framework.web.domain.AjaxResult;
import com.hongxun.common.utils.poi.ExcelUtil;

/**
 * 配电材料 信息操作处理
 * 
 * @author hongxun
 * @date 2019-03-19
 */
@Controller
@RequestMapping("/assets/iMaterial")
public class IMaterialController extends BaseController
{
    private String prefix = "assets/iMaterial";
	
	@Autowired
	private IIMaterialService iMaterialService;
	@Autowired
	private IIPointService iPointService;




	
//	@RequiresPermissions("assets:iMaterial:view")
	@GetMapping()
	public String iMaterial(IMaterial iMaterial , ModelMap modelMap)
	{
		String pointId = iMaterial.getPointId();

		IPoint iPoint = iPointService.selectIPointById(pointId);
		modelMap.put("lineId",iPoint.getLineId());	// 线路ID
		modelMap.put("byqId",iPoint.getByqId());	// 变压器ID
		modelMap.put("pointId",pointId);			// 点位ID
		return prefix + "/iMaterial";
	}
	
	/**
	 * 查询配电材料列表
	 */
//	@RequiresPermissions("assets:iMaterial:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(IMaterial iMaterial)
	{
		startPage();
        List<IMaterial> list = iMaterialService.selectIMaterialList(iMaterial);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出配电材料列表
	 */
	@RequiresPermissions("assets:iMaterial:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IMaterial iMaterial)
    {
    	List<IMaterial> list = iMaterialService.selectIMaterialList(iMaterial);
        ExcelUtil<IMaterial> util = new ExcelUtil<IMaterial>(IMaterial.class);
        return util.exportExcel(list, "iMaterial");
    }
	
	/**
	 * 新增配电材料
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存配电材料
	 */
	@RequiresPermissions("assets:iMaterial:add")
	@Log(title = "配电材料", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(IMaterial iMaterial)
	{		
		return toAjax(iMaterialService.insertIMaterial(iMaterial));
	}

	/**
	 * 修改配电材料
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		IMaterial iMaterial = iMaterialService.selectIMaterialById(id);
		mmap.put("iMaterial", iMaterial);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存配电材料
	 */
	@RequiresPermissions("assets:iMaterial:edit")
	@Log(title = "配电材料", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(IMaterial iMaterial)
	{		
		return toAjax(iMaterialService.updateIMaterial(iMaterial));
	}
	
	/**
	 * 删除配电材料
	 */
	@RequiresPermissions("assets:iMaterial:remove")
	@Log(title = "配电材料", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(iMaterialService.deleteIMaterialByIds(ids));
	}
	
}
